#!/bin/bash
# chkconfig:   2345 90 10
#LVS script for DR
. /etc/rc.d/init.d/functions
VIP=172.25.0.100
DIP=172.25.0.11
RIP1=172.25.0.31
RIP2=172.25.0.32
RIP3=172.25.0.33
PORT=80
# 
#description: hhahahah

case "$1" in
start)
  /sbin/ifconfig ens34:0 $VIP broadcast $VIP netmask 255.255.255.255 up
  /sbin/route add -host $VIP dev ens34:0

# Since this is the Director we must be able to forward packets 
  echo 1 > /proc/sys/net/ipv4/ip_forward
# 开启路由转发功能
# Clear all iptables rules. 
  /sbin/iptables -F

# Reset iptables counters. 
  /sbin/iptables -Z

# Clear all ipvsadm rules/services. 
  /sbin/ipvsadm -C

# Add an IP virtual service for VIP 192.168.0.219 port 80 
# In this recipe, we will use the round-robin scheduling method. 
# In production, however, you should use a weighted, dynamic scheduling method. 
  /sbin/ipvsadm -A -t $VIP:80 -s wrr

# Now direct packets for this VIP to 
# the real server IP (RIP) inside the cluster 
  /sbin/ipvsadm -a -t $VIP:80 -r $RIP1 -g -w 1
  /sbin/ipvsadm -a -t $VIP:80 -r $RIP2 -g -w 1
  /sbin/ipvsadm -a -t $VIP:80 -r $RIP3 -g -w 1
;;

stop)
# Stop forwarding packets 
  echo 0 > /proc/sys/net/ipv4/ip_forward

# Reset ipvsadm 
  /sbin/ipvsadm -C

# Bring down the VIP interface 
  /sbin/ifconfig ens34:0 down

#  echo "ipvs is stopped..." 
;;

*)
  echo "Usage: $0 {start|stop}" 
;;
esac